{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "data = json.load(open('/data/squad/train-v2.0.json'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import nltk\n",
    "#t,j,k = qas2para[uid2qasid[uid]]\n",
    "#original_data['data'][t]['paragraphs'][j]['qas'][k]\n",
    "with open('squad2_question.en', 'w', encoding='utf-8') as fout:\n",
    "    id2pos = dict()\n",
    "    cnt = 0\n",
    "    for t, d in enumerate(data['data']):\n",
    "        for j, p in enumerate(d['paragraphs']):\n",
    "            for k, qas in enumerate(p['qas']):\n",
    "                id2pos[cnt] = (t, j, k)\n",
    "                tok_q = nltk.word_tokenize(qas['question']) \n",
    "                #print(qas['question'])\n",
    "                qline = ' '.join(tok_q)\n",
    "                cnt += 1\n",
    "                fout.write('{}\\n'.format(qline))\n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "with open('squad2_question.en', 'r', encoding='utf-8') as fin:\n",
    "    ques = fin.readlines()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
